﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using nanoCMS.Blog.WebUI.Models;
using nanoCMS.Core;

namespace nanoCMS.Blog.WebUI.Controllers {
    public class BlogCategoryController : Controller {

        
		private BlogCategoryService blogCategoryService;

		public BlogCategoryController(WorldContext worldContext)
		{
			blogCategoryService = new BlogCategoryService(worldContext);
		}


		public ActionResult ListBlogCategories(int tenantID) {
			List<BlogCategoryVM> model = blogCategoryService.GetBlogCategoriesForTenant(tenantID);

			return PartialView("ListBlogCategories", model);
		}


		public ActionResult EditBlogCategory(int blogCategoryID) {

			return PartialView("EditBlogCategory", blogCategoryService.GetBlogCategory(blogCategoryID));
		}

        [HttpPost]
		public ActionResult EditBlogCategory(BlogCategoryVM model) {
			if (ModelState.IsValid)
			{
			    blogCategoryService.EditBlogCategory(model);
                return this.Content("removeForm");
			}
            return PartialView("EditBlogFieldsPartial", model);
		}

		public ActionResult AddBlogCategory() {
			BlogCategoryVM model = new BlogCategoryVM();
			return PartialView("AddBlogCategory", model);
		}


        [HttpPost]
        public ActionResult AddBlogCategory(BlogCategoryVM model)
        {
            if (ModelState.IsValid)
            {
                blogCategoryService.AddBlogCategory(model);
                return this.Content("removeForm");
            }
            return PartialView("EditBlogFieldsPartial", model);
        }

    }
}
